<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\BookSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '书籍管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="book-index box box-primary">
    <?= $this->render('@app/views/layouts/_tab.php') ?>
    <div class="box-header with-border">
        <?php if (\mdm\admin\components\Helper::checkRoute('create')) { ?>
            <?= Html::a('新增', ['create'], ['class' => 'btn btn-primary btn-flat']) ?>
        <?php } ?>
    </div>
    <div class="box-body table-responsive">
        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'layout' => "{items}\n{summary}\n{pager}",
            'columns' => [
                [
                    'attribute' => 'id',
                    'value' => function ($model) {
                        return $model->id;
                    }
                ],
                [
                    'attribute' => 'pid',
                    'value' => function ($model) {
                        return $model->pid;
                    }
                ],
                [
                    'attribute' => 'title',
                    'value' => function ($model) {
                        return $model->title;
                    }
                ],
                [
                    'attribute' => 'desc',
                    'value' => function ($model) {
                        return $model->desc;
                    }
                ],
                [
                    'attribute' => 'is_end',
                    'value' => function ($model) {
                        return $model->is_end;
                    }
                ],
                // 'is_hot',
                // 'sort',
                // 'status',
                // 'created_at',
                // 'updated_at',

                [
                    'class' => 'yii\grid\ActionColumn',
                    'template' => \mdm\admin\components\Helper::filterActionColumn('{update}{delete}'),
                    'buttons' => [
                        'update' => function ($url, $model, $key) {
                            return \yii\helpers\Html::a("<i class='fa fa-fw fa-edit'></i>编辑", ['update', 'id' => $key], ['class' => 'btn btn-primary']);
                        },
                        'delete' => function ($url, $model, $key) {
                            return \yii\helpers\Html::a("<i class='fa fa-fw fa-recycle'></i>删除", ['delete', 'id' => $key],
                                [
                                    'class' => 'btn btn-primary',
                                    'data' => [
                                        'confirm' => Yii::t('app', '是否确认删除?'),
                                        'method' => 'post'
                                    ]
                                ]
                            );
                        }
                    ],
                ],
            ],
        ]); ?>
    </div>
</div>
